﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessLogicLayer;
using DataAccessLayer;

namespace PresentationLayer
{
    public partial class ViewStationeryCatalogue : System.Web.UI.Page
    {
        ViewStationeryCatalogueControl viewcont;
        StationeryInventoryEntities1 ent;

        protected void Page_Load(object sender, EventArgs e)
        {
            viewcont = new ViewStationeryCatalogueControl();
            ent = new StationeryInventoryEntities1();

            if (!IsPostBack) {
                ddlCategory.DataSource = viewcont.getCatList();
                ddlCategory.DataTextField = "CategoryName";
                ddlCategory.DataValueField = "CategoryID";
                ddlCategory.DataBind();
                ddlCategory.Items.Insert(0, "All");
            }
            Binding();
        }
        public void Binding()
        {
            dgvCatalogue.DataSource = viewcont.getAllStationeryList();
            dgvCatalogue.DataBind();
        }

        protected void ddlCategory_SelectedIndexChanged1(object sender, EventArgs e)
        {
            if (ddlCategory.SelectedValue == "All")
            {
                Binding();
            }
            else {
                int catId = Convert.ToInt32(ddlCategory.SelectedValue.ToString());
                dgvCatalogue.DataSource = viewcont.getAllStationeryListByCatID(catId);
                dgvCatalogue.DataBind();

            }
         }

        protected void dgvCatalogue_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            dgvCatalogue.PageIndex = e.NewPageIndex;
            Binding();
        }


    }
}